package com.github.caijh.mall.utils;

import java.io.File;

import com.github.caijh.commons.util.DateUtils;
import com.github.caijh.mall.constants.Constants;
import lombok.Data;

/**
 * 上传文件的属性配置
 */
@Data
public class UploadSpecs {

    private String rootPath;

    private UploadType uploadType;
    private String module;
    private boolean isCompress;
    private String extSupported;
    private long limitSize = 1024 * 1024 * 2L; // 2M

    private String newFileName;
    private String extName;

    public String getRootPath() {
        if (!rootPath.endsWith(File.separator)) {
            rootPath = (rootPath + File.separator);
        }

        return rootPath.replace(" ", "").replace("//", "/");
    }

    public String getWebPath() {
        return this.getUploadType().getType()
                + File.separator + this.getModule() + File.separator + DateUtils.nowAsString(Constants.DATE_FORMAT_DATE).replace("-", "/") + File.separator;
    }

}
